package com.seocoo.worker.order.adapter;

import android.text.TextUtils;
import android.view.View;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.seocoo.worker.R;
import com.seocoo.worker.order.entity.RspOrderInstall;
import com.seocoo.worker.order.widget.OrderDetailAddressView;
import com.seocoo.worker.order.widget.rsp.RspOrderDetailAddress;

/**
 * author : Ssp
 * e-mail : 981297079@qq.com
 * date   : 2020/2/2320:32
 * desc   : 安装订单(星级工匠)
 * version: 1.0
 */
public class OrderInstallAdapter extends BaseQuickAdapter<RspOrderInstall, BaseViewHolder> {

    public OrderInstallAdapter() {
        super(R.layout.order_install_item);
    }

    @Override
    protected void convert(BaseViewHolder helper, RspOrderInstall item) {
        helper.setText(R.id.tv_time, item.getAddTime())
                .setText(R.id.tv_cargo_num, "共" + item.getGoodsCount() + "件商品");
        if (TextUtils.isEmpty(item.getCommission())) {
            helper.setGone(R.id.tv_money, false);
            helper.setGone(R.id.tv_money1, false);
        } else {
            helper.setGone(R.id.tv_money, true);
            helper.setGone(R.id.tv_money1, true);
            helper.setText(R.id.tv_money, "佣金￥" + item.getCommission());
        }
        initAddressView(helper, item);
        initBottomView(helper, item);

    }

    /**
     * 设置地址栏数据
     *
     * @param helper
     * @param item
     */
    private void initAddressView(BaseViewHolder helper, RspOrderInstall item) {
        OrderDetailAddressView addressView = helper.getView(R.id.order_detail_address_view);
        RspOrderDetailAddress rspOrderDetailAddress = new RspOrderDetailAddress();
        rspOrderDetailAddress.setCargoAddress(item.getMerchantName());
        rspOrderDetailAddress.setCargoAddressDetail(item.getMerchantProvince() + item.getMerchantCity() + item.getMerchantDistrict() + item.getMerchantAddress());
        rspOrderDetailAddress.setUserAddress(item.getUserProvince() + item.getUserCity() + item.getUserDistrict() + item.getUserCommunity() + item.getUserDoorPlate());
        rspOrderDetailAddress.setUserName(item.getConsignee());
        rspOrderDetailAddress.setUserPhone(item.getContact());
        rspOrderDetailAddress.setMerchantContact(item.getMerchantContact());
        rspOrderDetailAddress.setPickupCode(item.getPickupCode());
        addressView.initData(rspOrderDetailAddress);
    }

    private void initBottomView(BaseViewHolder helper, RspOrderInstall item) {
        helper.addOnClickListener(R.id.tv_cancel)
                .addOnClickListener(R.id.tv_receiving)
                .addOnClickListener(R.id.tv_relevance_friends)
                .addOnClickListener(R.id.tv_appointment_install_time)
                .addOnClickListener(R.id.tv_evaluate_workmate)
                .addOnClickListener(R.id.tv_order_receiving);
        //400 取消安装 401 待接单 402 待取货 403 待安装 501 待评价
        String status = item.getOrderStatus();
        if (TextUtils.equals("401", status)) {

            helper.setGone(R.id.tv_order_receiving, true);
        } else {
            helper.setGone(R.id.tv_order_receiving, false);
        }

        if (TextUtils.equals("402", status)) {
            helper.setGone(R.id.tv_receiving, true);

        } else {
            helper.setGone(R.id.tv_receiving, false);

        }

        String installTime = item.getInstallTime();

        if (TextUtils.equals("402", status) && TextUtils.isEmpty(installTime)) {
            helper.setGone(R.id.tv_cancel, true);
        } else {
            helper.setGone(R.id.tv_cancel, false);
        }
        if (TextUtils.equals("403", status) && TextUtils.isEmpty(installTime)) {
            helper.setGone(R.id.tv_appointment_install_time, true);
        } else {
            helper.setGone(R.id.tv_appointment_install_time, false);
        }

        String isAppraise = item.getIsAppraise();
        if (TextUtils.equals("501", status) && TextUtils.equals("0", isAppraise)) {
            helper.setGone(R.id.tv_evaluate_workmate, true);
        } else {
            helper.setGone(R.id.tv_evaluate_workmate, false);
        }

        if (TextUtils.equals("403", status) && !TextUtils.isEmpty(installTime)) {
            helper.setGone(R.id.tv_relevance_friends, true);
        } else {
            helper.setGone(R.id.tv_relevance_friends, false);
        }

    }
}
